package com.ruoyi.dispatch.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.dispatch.enums.LeaderDutyReportCol;
import com.ruoyi.dispatch.vo.LeaderDutyReportVO;
import com.ruoyi.framework.utils.BeanCopyUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dispatch.domain.LeaderDutyReport;
import com.ruoyi.dispatch.service.ILeaderDutyReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 矿领导带班Controller
 * 
 * @author maxing
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/dispatch/leaderDuty")
@Anonymous
public class LeaderDutyReportController extends BaseController
{
    @Autowired
    private ILeaderDutyReportService leaderDutyReportService;

    /**
     * 查询矿领导带班列表
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:leaderDuty:list')")
    @GetMapping("/list")
    public TableDataInfo list(LeaderDutyReport leaderDutyReport,String[] columnArray)
    {
        startPage();
        List<LeaderDutyReport> list = leaderDutyReportService.selectLeaderDutyReportList(leaderDutyReport);

        //组装展示列名信息
        List<Map<String,String>> columns = null;
        if(columnArray!=null && columnArray.length!=0){
            columns = leaderDutyReportService.handleColumnMap(columnArray);
        }
        TableDataInfo tableData =  getDataTable(list);
        tableData.setColumns(columns);

        return tableData;
    }

    /**
     * 导出矿领导带班列表
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:leaderDuty:export')")
    @Log(title = "矿领导带班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LeaderDutyReport leaderDutyReport)
    {
        List<LeaderDutyReport> list = leaderDutyReportService.selectLeaderDutyReportList(leaderDutyReport);
        ExcelUtil<LeaderDutyReport> util = new ExcelUtil<LeaderDutyReport>(LeaderDutyReport.class);
        util.exportExcel(response, list, "矿领导带班数据");
    }

    /**
     * 获取矿领导带班详细信息
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:leaderDuty:query')")
    @GetMapping(value = "/{dutyId}")
    public AjaxResult getInfo(@PathVariable("dutyId") Long dutyId)
    {
        return success(leaderDutyReportService.selectLeaderDutyReportByDutyId(dutyId));
    }

    /**
     * 新增矿领导带班
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:leaderDuty:add')")
    @Log(title = "矿领导带班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LeaderDutyReport leaderDutyReport)
    {
        //插入数据
        int insertResult = leaderDutyReportService.insertLeaderDutyReport(leaderDutyReport);

        //查询此次新增的记录
        LeaderDutyReport report = leaderDutyReportService.selectLeaderDutyReportByDutyId(leaderDutyReport.getDutyId());
        LeaderDutyReportVO vo = BeanCopyUtils.copyProperties(report,LeaderDutyReportVO.class);
        //组装默认展示的列信息
        vo.setDisplayCols(LeaderDutyReportCol.getDefalutCols());

        return toAjax(insertResult,vo);
    }

    /**
     * 修改矿领导带班
     */
   // @PreAuthorize("@ss.hasPermi('dispatch:leaderDuty:edit')")
    @Log(title = "矿领导带班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LeaderDutyReport leaderDutyReport)
    {
        return toAjax(leaderDutyReportService.updateLeaderDutyReport(leaderDutyReport));
    }

    /**
     * 删除矿领导带班
     */
    //@PreAuthorize("@ss.hasPermi('dispatch:leaderDuty:remove')")
    @Log(title = "矿领导带班", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dutyIds}")
    public AjaxResult remove(@PathVariable Long[] dutyIds)
    {
        return toAjax(leaderDutyReportService.deleteLeaderDutyReportByDutyIds(dutyIds));
    }
}
